package com.ok.cartoon.controller;


import com.ok.cartoon.domain.po.OkArea;
import com.ok.cartoon.service.IOkAreaService;
import com.ok.common.domain.po.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 漫画地区 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-04-28
 */
@Api(tags = "漫画地区相关接口")
@RestController
@RequestMapping("/area")
@RequiredArgsConstructor
public class OkAreaController {

    private final IOkAreaService okAreaService;

    @ApiOperation(value = "添加地区")
    @PostMapping("/add")
    public Result add(@RequestParam String country){
        OkArea okArea = new OkArea();
        okArea.setCountry(country);
        okAreaService.save(okArea);
        return Result.success("添加成功");
    }

    @ApiOperation(value = "删除地区")
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        okAreaService.removeWith(id);
        return Result.success("删除成功");
    }

    @ApiOperation(value = "查询地区")
    @GetMapping("/list")
    public Result list(){
        List<OkArea> list = okAreaService.list();
        return Result.success(list);
    }

    @ApiOperation(value = "修改地区")
    @PutMapping("/update")
    public Result update(@RequestBody OkArea okArea){
        okAreaService.updateById(okArea);
        return Result.success("修改成功");
    }
}
